package com.fourhats.dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.fourhats.dao.PriceDAO;
import com.fourhats.model.Price;

@Repository
public class PriceDAOImpl extends GenericDAOImpl<Price, Long> implements PriceDAO {

	protected PriceDAOImpl() {
		super(Price.class.getName());

	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional
	public List<Price> getEnabledPricesByItemAndPlace(long itemId, List<Long> placeIds) {
		DetachedCriteria criteria = DetachedCriteria.forEntityName(entityName);
        criteria.add(Restrictions.eq("item.id", itemId));
        criteria.add(Restrictions.in("place.id", placeIds));
        criteria.add(Restrictions.eq("enable", true));
        return getHibernateTemplate().findByCriteria(criteria);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional
	public List<Price> getHistoricalPricesByItemAndPlace(long itemId) {
		DetachedCriteria criteria = DetachedCriteria.forEntityName(entityName);
        criteria.add(Restrictions.eq("item.id", itemId));
        criteria.add(Restrictions.eq("enable", true));
        return getHibernateTemplate().findByCriteria(criteria);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional
	public List<Price> getHistoricalPricesByItemAndPlace(long itemId, Long placeId) {
		DetachedCriteria criteria = DetachedCriteria.forEntityName(entityName);
        criteria.add(Restrictions.eq("item.id", itemId));
        criteria.add(Restrictions.eq("place.id", placeId));
        criteria.add(Restrictions.eq("enable", true));
        return getHibernateTemplate().findByCriteria(criteria);
	}
}
